package com.renting.modules.sys.web;

import com.alibaba.fastjson.JSONObject;
import com.renting.common.config.HttpStatusConstant;
import com.renting.common.entity.Result;
import com.renting.common.entity.ResultList;
import com.renting.modules.sys.dao.MenuDao;
import com.renting.modules.sys.entity.Menu;
import com.renting.modules.sys.service.MenuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * Created by Administrator on 2018/4/9.
 */
@RestController
@CrossOrigin("*")
public class MenuController {

    @Autowired
    MenuService menuService;

    @RequestMapping(value = "v1/sys/menus" ,method = RequestMethod.GET)
    public String menus(Menu menu) {
        ResultList<Menu> resultList = new ResultList<Menu>();
        List<Menu> menuList = menuService.findAll(menu);
        resultList.setData(menuList);
        return resultList.toJSONString();
    }

    @RequestMapping(value = "v1/sys/menus" ,method = RequestMethod.POST)
    public String AddMenu(@RequestBody Menu menu) {
        Result result = new Result();
        if(menuService.save(menu)){
            result.setStatus(HttpStatusConstant.SUCCESS);
        }

        return result.toJSONString();
    }
}
